<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">
    
    <title>Form Layouts</title>
    <link href="/public/js/summernote/dist/summernote.css" rel="stylesheet">
    <!--multi-select-->
    <link rel="stylesheet" type="text/css" href="/public/js/jquery-multi-select/css/multi-select.css" />

    <!--icheck-->
    <link href="/public/js/iCheck/skins/minimal/minimal.css" rel="stylesheet">
    <link href="/public/js/iCheck/skins/minimal/green.css" rel="stylesheet">
    <script language="javascript">
        function RunOnBeforeUnload() {window.onbeforeunload = function(){ return ""; } }
    </script>
    <?php $this->load->view('library/header');?>
</head>

<body onload="RunOnBeforeUnload()" class="sticky-header">

    <?php $this->load->view('library/left');?>
    
    <!-- main content start-->
    <div class="main-content" >
        
        <?php $this->load->view('library/top');?>
        
        <!-- page heading start-->
        <div class="page-heading">
            <h3>
                添加商品
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">Forms</a>
                </li>
                <li class="active"> Forms Layouts </li>
            </ul>
        </div>
        <!-- page heading end-->
        
        <!--body wrapper start-->
        <section class="wrapper">
            <div class="row">
            <div class="col-md-12">
            <!-- page start-->
            <section class="panel">
                <header class="panel-heading">
                    Multiple Select
                    <span class="tools pull-right">
                                <a class="fa fa-chevron-down" href="javascript:;"></a>
                                <a class="fa fa-times" href="javascript:;"></a>
                             </span>
                </header>
                <form id="commentForm" class="form-horizontal adminex-form" method="post">
                <div class="panel-body">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">产品名称</label>
                        <div class="col-sm-6">
                            <input type="text" name="goods_name" class="form-control" value="<?php echo $shopify_goods['goods_name'];?>" />
                            <span class="help-block">
                                <span style="margin-right: 15px;">功能:</span>
                                <a class="daxie" style="margin-right: 10px;" href="javascript:;">大写</a>
                                <a class="xiaoxie" style="margin-right: 10px;" href="javascript:;">小写</a>
                            </span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">产品属性</label>
                        <div class="col-sm-4 icheck">
                            <div class="minimal-green single-row">
                                <div class="checkbox ">
                                    <input type="checkbox" name="is_sales" value="1" <?php echo $shopify_goods['is_sales'] ? 'checked' : '';?>>
                                    <label>是否上架</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-group ">
                        <label for="curl" class="control-label col-lg-2">价格</label>
                        <div class="col-lg-2">
                            <div class="input-group">
                                <span class="input-group-addon">$</span>
                                <input type="text" value="<?php echo $shopify_goods['market_price'];?>" name="market_price" class="form-control" placeholder="原价">
                            </div>
                            <!--<span class="help-block">
                                <span style="margin-right: 15px;">功能:</span>
                                <a style="margin-right: 10px;" href="javascript:;">同步</a>
                                <a href="javascript:;">不同步</a>
                            </span>-->
                        </div>
                        <div class="col-lg-2">
                            <div class="input-group">
                                <span class="input-group-addon">$</span>
                                <input type="text" value="<?php echo $shopify_goods['shop_price'];?>" name="shop_price" class="form-control" placeholder="售价">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">产品分类</label>
                        <div class="col-sm-10">
                            <select name="cate_name" class="form-control">
                                <option value="">选择分类</option>
                                <?php foreach ($web_info['info']['cate_arr'] as $cate) :?>
                                    <option <?php echo $shopify_goods['cate_name'] == $cate ? 'selected' : '';?> value="<?php echo $cate;?>"><?php echo $cate;?></option>
                                <?php endforeach;?>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">产品标签</label>
                        <div class="col-sm-10">
                            <?php foreach ($tags as $k=>$v) :?>
                                <span style="margin-right: 55px;">
                                <input type="checkbox" name="tags[]" value="<?php echo $v['id'];?>"<?php if($v['che']){echo 'checked';}?>><?php echo $v['tags_name'];?></span>
                                <?php endforeach;?>
                            <!-- <select name="tags[]" multiple class="form-control">
                                <?php foreach ($web_info['info']['tags_arr'] as $tags) :?>
                                    <option <?php echo strpos(",{$shopify_goods['tags']},", ",$tags,") !== false ? 'selected' : '';?> value="<?php echo $tags;?>"><?php echo $tags;?></option>
                                <?php endforeach;?>
                            </select> -->
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">上架SKU</label>
                
                        <div class="col-md-10">
                            <select multiple="multiple" class="multi-select" id="my_multi_select1"
                                    name="sku[]">
                                <?php foreach ($goods['sku'] as $k => $sku) :?>
                                    <option value="<?php echo $k;?>" <?php echo $variants[$k] ? 'selected' : '';?>><?php echo $sku['size'] . '-' . $sku['color'];?></option>
                                <?php endforeach;?>
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">产品描述</label>
                        <div class="col-sm-10">
                            <textarea id="summernote" name="summernote" class="form-control" cols="4" rows="9"><?php echo $shopify_goods['body_html'];?></textarea>
                            <!--<span class="help-block">
                                <span style="margin-right: 15px;">功能:</span>
                                
                                <a style="margin-right: 10px;" href="javascript:;">同步</a>
                                <a href="javascript:;">不同步</a>
                            </span>-->
                        </div>
                    </div>
                </div>
                <footer class="panel-footer">
                    <button type="submit" name="handle_type" value="0" class="btn btn-post pull-right btn-big">提交信息</button>
                    <ul class="nav nav-pills p-option"></ul>
                </footer>
                </form>
            </section>
            <!-- page end-->
            </div>
        </div>
        </section>
        <!--body wrapper end-->
        
        <!--footer section start-->
        <footer>
            2014 &copy; AdminEx by
        </footer>
        <!--footer section end-->
    
    
    </div>
    <!-- main content end-->
</section>

<?php $this->load->view('library/footer');?>

<!--编辑器-->
<script src="/public/js/summernote/dist/summernote.js"></script>
<script src="/public/js/summernote/dist/lang/summernote-zh-CN.js"></script>

<!--icheck -->
<script src="/public/js/iCheck/jquery.icheck.js"></script>
<script src="/public/js/icheck-init.js"></script>

<!--multi-select-->
<script type="text/javascript" src="/public/js/jquery-multi-select/js/jquery.multi-select.js"></script>
<script type="text/javascript" src="/public/js/jquery-multi-select/js/jquery.quicksearch.js"></script>
<script src="/public/js/multi-select-init.js"></script>

<script src="/public/js/nestable/jquery.nestable.js"></script>
<script src="/public/js/nestable-init.js"></script>

<!--common scripts for all pages-->
<script src="/public/js/scripts.js"></script>

<script>
    function replaceStr(str){ // 正则法
        str = str.toLowerCase();
        var reg = /\b(\w)|\s(\w)/g; //  \b判断边界\s判断空格
        return str.replace(reg,function(m){
            return m.toUpperCase()
        });
    }
    jQuery(document).ready(function(){
        
        $('.xiaoxie').click(function () {
            var str = replaceStr($('input[name="goods_name"]').val());
            $('input[name="goods_name"]').val(str);
        });
        $('.daxie').click(function () {
            var str = $('input[name="goods_name"]').val();
            $('input[name="goods_name"]').val(str.toUpperCase());
        });

        $('#summernote').summernote({
            tabsize: 2,
            height: 300,
            lang: 'zh-CN'
        });

        $('#commentForm').submit(function () {

            t = setTimeout(function() {
                $('.panel-footer .btn-big').attr('disabled','disabled').addClass('btn-submit-disabled').html('正在提交，请稍等...');
            }, 200);


            var data = new FormData(this);

            $.ajax({
                type: 'POST',
                url: '<?php echo base_url('ShopifyGoods/set'. ($shopify_goods ? "/sg_id/{$shopify_goods['sg_id']}" : ''));?>',
                data: data,
                success: function (data) {
                    clearTimeout(t);
                    if (data.status != 'success') {
                        swal({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: 1500,
                            showConfirmButton: false
                        });
                        $('.panel-footer .btn-big').attr("disabled",false).removeClass('btn-submit-disabled').html('提交信息');
                    } else {
                        swal({
                            title: data.info,
                            text: '2秒后关闭',
                            type: data.status,
                            allowOutsideClick: false,
                            timer: data.stop ? data.stop : 1500,
                            showConfirmButton: false
                        }).then(function(isConfirm) {
                            window.onbeforeunload = '';
                            window.location.href = '<?php echo base_url('ShopifyGoods/index');?>';
                        });
                        $('.panel-footer .btn-big').removeClass('btn-submit-disabled').html(data.info);
                    }

                },
                dataType:'json',
                cache: false,
                contentType: false,
                processData: false
            });

            return false;
        });
    });
</script>

</body>
</html>
